﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESF.SSO.Presenter.Admin.BasicReference;
using ESF.Web.Pages;
using ESF.Web;
using ESF.General.Entity;
using ESF.SSO.Core.Entities.BasicReferences;
using ESF.General;
using ESF.Web.ServerControls;

#endregion


public partial class BasicReference_BrowseBasicReferences : BaseCustomBrowsePagedPage<BasicReference, BrowseBasicReferencePresenter, IBrowseBasicReferenceViewer>, IBrowseBasicReferenceViewer
{
	#region Carga Inicial
	
	protected void Page_Load (object sender, EventArgs e)
	{
		ScriptManager.GetCurrent (this).RegisterAsyncPostBackControl (dpggrvResults);
	
		_Presenter = new BrowseBasicReferencePresenter (this);
		
		if (!IsPostBack)
		{
			BasicReferenceTypeID = TextHelper.GetInt (Request.QueryString ["BasicReferenceTypeID"]);
			
			frmEnabled = BasicReferenceTypeID > 0;
			
			_Presenter.Load ();
			
			btnNew.Attributes ["onclick"] = JS.GenerateGoToFinal (string.Format ("EditBasicReference.aspx?BasicReferenceTypeID={0}", BasicReferenceTypeID));
		}
	}
	
	#endregion


	#region Funciones Sobreescritas

	protected override DataPagging GetDataPagging()
	{
		return dpggrvResults;
	}


	protected override Button GetDeleteButton()
	{
		return btnDelete;
	}


	protected override GridView GetGridView()
	{
		return grvResults;
	}
	

	public override IEnumerable<BasicReference> GetSelectedItems(IEnumerable<string> pIDs)
	{
		foreach (string ID in base.SelectedIDs)
		{
			yield return new BasicReference () { ID = TextHelper.GetInt (ID) };
		}
	}
	
	#endregion


	#region Miembros de IBrowseBasicReferenceViewer

	public string frmTitle
	{
		set
		{
			Title = value;
			lblTitle.Text = value;
		}
	}


	public string Code
	{
		get
		{
			return txtCode.Text;
		}
		set
		{
			txtCode.Text = value;
		}
	}

	public string Name
	{
		get
		{
			return txtName.Text;
		}
		set
		{
			txtName.Text = value;
		}
	}
	
	
	public int BasicReferenceTypeID
	{
		get
		{
			return Convert.ToInt32 (ViewState ["BasicReferenceTypeID"]);
		}
		set
		{
			ViewState ["BasicReferenceTypeID"] = value;
		}
	}

	#endregion
	
	
	#region Eventos de la Grilla
	
	protected void grvResults_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		BasicReference item;
		
		HyperLink lnkEdit;
		
	
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			item = e.Row.DataItem as BasicReference;
		
			SetHiddenFieldForID (e.Row, item.ID.Value);
			
			lnkEdit = (e.Row.FindControl ("lnkEdit") as HyperLink);
			
			lnkEdit.Text = item.Name;
			lnkEdit.NavigateUrl = string.Format ("EditBasicReference.aspx?ItemID={0}&BasicReferenceTypeID={1}", item.ID, BasicReferenceTypeID);
		}
	}
	
	#endregion
}
